package divinity.weapons
{
	import flash.events.Event;
	import flash.geom.Point;
	
	import divinity.objects.ActiveObject;
	import divinity.fx.particles.definitions.Standard;

	public class ParticleWeapon extends Weapon
	{
		
		private var _endX:Number;
		private var _endY:Number;
		public function ParticleWeapon(wld:*,firedBy:*,direction:Point)
		{
			super(wld,firedBy,direction);
			mass=0;
			speed=700;
		}
		override public function init(e:Event)
		{
			
			getCollision();
			super.init(e);
			img=new ship();
			
			
			
			
			
		}
		private function getCollision()
		{
			var tx:Number;
			var ty:Number;
			var n:int=0;
			
			while(n<1000)
			{
				tx=Math.round(x+(n*vx));
				ty=Math.round(y+(n*vy));
				
				var checkHeight:int=world.getHeight(tx,ty);				
				if(checkHeight>myHeight)
				{					
					_endX=tx;
					_endY=ty;				
					break;
				}
				n++;
			}
			
		}
		override protected function moving():void
		{
			super.moving();
			if(vx>0)
			{
				if(_newx>_endX)
				{
					_newx=_endX;
					alive=false;
					hitSolid();
				}			
			}
			else
			{
				if(_newx<_endX)
				{
					_newx=_endX;
					alive=false;
					hitSolid();
				}
			}
			/*
			*
			*/
			if(vy>0)
			{
				if(_newy>_endY)
				{
					_newy=_endY;
					alive=false;
					hitSolid();
				}			
			}
			else
			{
				if(_newy<_endY)
				{
					_newy=_endY;
					alive=false;
					hitSolid();
				}
			}
			/*
			*
			*/
			if(_newx>world.worldWidth)
			{
				alive=false;
			}
			if(_newx<0)
			{
				alive=false;
			}
			if(_newy>world.worldHeight)
			{
				alive=false;
			}
			if(_newy<0)
			{
				alive=false;
			}
			
			
		}
		override protected function collision():void
		{
			
		}
		
		override protected function dead()
		{
			
			super.dead();
		}
		override protected function makeMove():void
		{
			super.makeMove();
			leaveTrail();
		}
		protected  function leaveTrail():void
		{
			world.vfx.makeVFX(this,1,Standard.SHORT_TRAIL);
		}
		protected function hitSolid():void
		{
			world.vfx.anim("explosion",this,300,1);
			world.vfx.makeVFX(this,20,Standard.SMALL_EXPLOSION);
			world.vfx.shake(20,6);
		}
	}
}